import { fileURLToPath, URL } from 'node:url'

import { defineConfig,loadEnv  } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import viteCompression from "vite-plugin-compression";
import legacyPlugin from '@vitejs/plugin-legacy'
import AutoImport from 'unplugin-auto-import/vite'
const path = require("path");
// https://vitejs.dev/config/
export default defineConfig(({command,mode}) =>{
    loadEnv(mode,process.cwd())
    return {
      base: './',
      plugins: [
        vue(),
        vueJsx(),
        viteCompression({
          verbose:true,
          disable:false,
          deleteOriginFile:false,
          threshold:10240,
          algorithm:'gzip',
          ext:'.gz'
        }),
        AutoImport ({
          imports: ["vue", "vue-router"], // 自动导入vue和vue-router相关函数
        }),
        legacyPlugin({
          targets:['ie >= 11'],
          additionalLegacyPolyfills:['regenerator-runtime/runtime']
        })
      ],
      resolve: {
        alias: {
          '@': fileURLToPath(new URL('./src', import.meta.url))
        }
      },
      server:{
        hmr:true,
        open:true,
        port:8080,
        host: '0.0.0.0',
        https:false,//是否打开HTTPs
        proxy:{
          [process.env.VITE_APP_BASE_API]:{
            target:'http://121.36.52.19:8082',
            changeOrigin:true,
            rewrite:(path) => path.replace(process.env.VITE_APP_BASE_API,'')
          }
        }
      },
      build: {
        assetsDir: "static",
      }
    }
})
